<?php
  /*
   +--------------------------------------------------------------------------
   |   phpBIZ v m2.1  full version
   |   ========================================
   |   by taft@wjl.cn yejun@wjl.cn
   |   http://www.phpbiz.cn http://www.wjl.cn
   |   all rights reserved
   +---------------------------------------------------------------------------
   |
   |   > 最后修改日期：2005-4-30 2006-2-8
   |
   +--------------------------------------------------------------------------
  */

error_reporting  (E_ERROR | E_PARSE );
//error_reporting (E_ALL);
set_magic_quotes_runtime(0);
define('ROOT_PATH','./');
class Debug {
  function startTimer() {
    global $starttime;
    $mtime = microtime ();
    $mtime = explode (' ', $mtime);
    $mtime = $mtime[1] + $mtime[0];
    $starttime = $mtime;
  }
  function endTimer() {
    global $starttime;
    $mtime = microtime ();
    $mtime = explode (' ', $mtime);
    $mtime = $mtime[1] + $mtime[0];
    $endtime = $mtime;
    $totaltime = round (($endtime - $starttime), 5);
    return $totaltime;
  }
}

require ROOT_PATH."conf_global.php";
require ROOT_PATH."constant.php";
require ROOT_PATH."source/libs/smarty/Smarty.class.php";
require ROOT_PATH."source/libs/xajax/xajax.inc.php";
require ROOT_PATH."source/functions.php";
require ROOT_PATH."source/libs/upload.class.php";

//--------------------------------
// The clocks a' tickin'
//--------------------------------
$Debug = new Debug;
$Debug->startTimer();              

//--------------------------------

$BIZ = new biz_smarty;
$SESS = new session;

//--------------------------------
//  load incoming var 
//--------------------------------

$INCOME = $BIZ -> parse_incoming();
//--------------------------------
//  load the db driver class
//--------------------------------

$CONF['sql_driver'] = !$CONF['sql_driver'] ? 'mySQL' : $CONF['sql_driver'];
define('TO_REQUIRE', ROOT_PATH."source/Drivers/".$CONF['sql_driver'].".".$CONF['php_ext']);  
require (TO_REQUIRE);

$DB = new DB;
$DB->info['host'] = $CONF['sql_host'];
$DB->info['usr']  = $CONF['sql_user'];
$DB->info['pwd']  = $CONF['sql_pwd'];
$DB->info['db']   = $CONF['sql_db'];
$DB->db_connect();

//--------------------------------
//  Set up the session ID stuff
//--------------------------------

$BIZ->seller    = $SESS->authorise();
$BIZ->location  = $SESS->location;

//------------------------------------
//refill upload stuff
//------------------------------------
if(!$CONF['single_upload_dir'])
  {
    $CONF['upload_dir'] = $CONF['upload_base_dir'].date("Y")."/".date("m")."/";
  }

//--------------------------------------
//init cache
//--------------------------------------
$cache = new cache;
require ROOT_PATH."source/Cache/index_inc.".$CONF['php_ext'];   //index cache file

//--------------------------------
// Decide what to do
//--------------------------------

//1 find the url format

$str = $_SERVER['HTTP_HOST'];
$host = explode(".",$str);
if( $_SERVER['HTTP_HOST'] != $_SERVER['SERVER_ADDR'] && count($host) == count($CONF['domain'])+1 )
  {
    $DB -> db_query("SELECT seller_id FROM biz_seller WHERE seller_logaccount ='".$host[0]."'" );
    $re = $DB -> db_fetch_row();
    if( $re['seller_id'] && !$INCOME['act'] ) 
      {
	$INCOME['SELLER_ID'] = $re['seller_id'];
	require ROOT_PATH."source/".SellerDetail.".".$CONF['php_ext']; 
	exit;
      }
  }
//---------------------------------
$BIZ -> assign("seller",$BIZ->seller);
//print_r($BIZ->seller);
$BIZ -> assign("domain",$CONF['domain']);
$BIZ -> assign("index_url",$CONF['biz_url']);
$choice = array(
		"idx"      => "Main",
		"Reg"      => "Register",
		"Login"    => "Login",           //00 -> form ,01-> do login ,02 -> do logout
		"Members"  => "Memberlist",
		"Help"     => "Help",
		"Seller"   => "Sellercp",
		"Lst"      => "List",
		"sd"       => "ShopDetail",
		"gd"       => "GoodsDetail",
		"mes"      => "Read",
		"favors"   =>"Favors",
		"Promote"  =>"Promote",
		"Diyc"     =>"Diyc",
		"Adver"    =>"Adver",
		"Sharelink"=>"Sharelink",
		"User"     =>"Usercp",
		"Search"   =>"Search",
		"ListM"    =>"ListMessage",
		"DetailM"  =>"DetailMessage",
		"statics"  =>"Static",
		"Help"     =>"Help",
		"caveat"   =>"Caveat",
		"order"    =>"Order",
		"Seller2"  =>"Sellercp2",
		"Money"    =>"Money",
		"Bid"		=>"Bid",
		"showBid"  =>"showBid",
		"fgt"      =>"forget",
		"attpic"	=>"attachpic"
		);

if (! isset($choice[ $INCOME['act'] ]) )
  {  

    $INCOME['act'] = 'idx';
  }

require ROOT_PATH."source/".$choice[ $INCOME['act'] ].".".$CONF['php_ext']; 

?>
